/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package reportcenter.auth;

/**
 *
 * @author renan
 */
import org.acegisecurity.Authentication;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.context.SecurityContextHolder;
 
public class CurrentUser {
    
    private Authentication auth;
    
    public CurrentUser() {
	this.auth = (SecurityContextHolder.getContext().getAuthentication());
    }
    
    public String grantedRoles(){
        GrantedAuthority[] roles = auth.getAuthorities();
            
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < roles.length; i++) {
                GrantedAuthority grantedAuthority = roles[i];
                builder.append("'");
                builder.append(grantedAuthority);
                builder.append("'");
                if(roles.length - 1 != i){
                    builder.append(",");
                }
            }
            
            return builder.toString();
    }
    
    public static void main(String[] args) {
        String[] roles = {"1","2","3", "4"};
        StringBuilder builder = new StringBuilder();
            for (int i = 0; i < roles.length; i++) {
                builder.append("'");
                builder.append(roles[i]);
                builder.append("'");
                if(roles.length - 1 != i){
                    builder.append(",");
                }
            }
        System.out.println(builder.toString());
    }
}